package com.action;


import java.io.IOException;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.po.Store;
import com.service.StoreService;
import com.util.DataFormat;
import com.util.FileUtil;
import com.vo.StoreForm;


@Controller("store")
public class StoreAction extends ActionSupport{
	private StoreForm storeForm;
	private int id;
	private boolean update=false;
	@Autowired
	private StoreService storeService;

	public StoreForm getStoreForm() {
		return storeForm;
	}
	public void setStoreForm(StoreForm storeForm) {
		this.storeForm = storeForm;
	}
	
	public void setId(int id) {
		this.id = id;
	}
	
	public String add() {
		HttpSession session=ServletActionContext.getRequest().getSession();
		Store store=DataFormat.StoreFormat(storeForm);
		System.out.println("........"+store);
		storeService.add(store);
		session.setAttribute("store", store);
		return "addStore";
	}
	
	public String seletById(){
		HttpSession session=ServletActionContext.getRequest().getSession();
		System.out.println(id);
		Store store=storeService.selectById(id);
		System.out.println("selectByid........."+store);	
		session.setAttribute("store", store);
		if(update==false){
			return "selectById";
		}
		else{
			return "updateById";
		}
	}
	
	public void updateStoreById(){
		Store store=DataFormat.StoreFormat(storeForm);
		System.out.println("更新的..."+store);
		storeService.updateStore(store);
		System.out.println("更新了id为:"+id);
	}
	
	
	public void delStore(){
		 storeService.delStore(id);
		 System.out.println("删除id为:"+id);
	}
}
